<html>
    <head></head>
    <body>
    <label>当前分类</label>
        <form method="post" action="add_cata.php">
        <select id="catalog" name="catalog">
            
            <option value="0">请选择</option>
                <?php
                    include_once "conn.php";
                    $sql = "SELECT * FROM catalog WHERE is_del = 1";
                    $query = mysqli_query($conn,$sql);
                    while($row = mysqli_fetch_array($query)){
                ?>
                        <option value="<?php echo $row['id']?>"><?php echo $row['name']?></option>
                <?php
                    }   
                ?>
        </select>       
        <button type="submit">删除</button>
        </form>
            <?php
                    if ($_POST['cata']){
                    $cata = $_POST['cata'];
                    $sql = "INSERT INTO catalog (name) values ('".$cata."')";
                    print_r($sql);
                    $query = mysqli_query($conn,$sql);
                    header('Refresh:0');
                }
                if ($_POST['catalog']){
                    $cata = $_POST['catalog'];
                    $sql = "UPDATE catalog SET is_del = 0 WHERE id = ".$cata;
                    $query = mysqli_query($conn,$sql);
                    header('Refresh:0');
                }
            ?>
        
        <form method="post" action='add_cata.php'>
            添加分类：<input name="cata" type="text" >
            <button type="submit" >确定</button>
        </form>
    </body>
</html>